package org.springside.examples.crawler;

import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class JCFoodball2 {

	public static void main(String[] args) throws Exception {
		String url="http://www.okooo.com/jingcai/2015-05-17/";
		
	    /** HtmlUnit请求web页面 */  
	    WebClient wc = new WebClient(BrowserVersion.CHROME);  
	    wc.getOptions().setUseInsecureSSL(true);  
	    wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true  
	    wc.getOptions().setCssEnabled(false); // 禁用css支持  
	    wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常  
	    wc.getOptions().setTimeout(50000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待  
	    wc.getOptions().setDoNotTrackEnabled(false);  
	    HtmlPage page = wc.getPage(url);  
	  
		Document doc=null;

		try {
			doc = Jsoup.parse(page.asXml());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Elements content_div = doc.select("#content");
		//System.out.println(content_div.html());
		
		Elements touzhu_boxs = content_div.select("div[class=touzhu_1]");
		System.out.println(touzhu_boxs.size());
		int index =1;
		for(Element touzhu_box:touzhu_boxs){
			System.out.print("索引:"+index++);
			//id
			System.out.print(" ID:"+touzhu_box.attr("data-mid"));
			//序列
			System.out.print(" 序列:"+touzhu_box.select("span[class=xulie]").text());
			System.out.print(" 联赛:"+touzhu_box.select("a.saiming").text());
			System.out.print(" 比赛时间:"+touzhu_box.select("div[class=shijian]").attr("title"));
			System.out.println();
			//比赛不让球
			System.out.print(" 主队:"+touzhu_box.select("div.shenpf div.zhu div.zhum").text());
			System.out.print(" 主队排名:"+touzhu_box.select("div.shenpf div.zhu div.paim").text());
			System.out.print(" 赔率 主胜:"+touzhu_box.select("div.shenpf div.zhu div.peilv").text());
			System.out.print(" 赔率 平:"+touzhu_box.select("div.shenpf div.ping div.peilv").text());
			System.out.print(" 客队:"+touzhu_box.select("div.shenpf div.fu div.zhum").text());
			System.out.print(" 客队排名:"+touzhu_box.select("div.shenpf div.fu div.paim").text());
			System.out.print(" 赔率 客胜:"+touzhu_box.select("div.shenpf div.fu div.peilv").text());
			//比赛让球
			System.out.print(" 让球 让球数:"+touzhu_box.select("div.rangqiuspf div.zhu div.zhud>span").text());
			System.out.print(" 让球 赔率 主胜:"+touzhu_box.select("div.rangqiuspf div.zhu div.peilv").text());
			System.out.print(" 让球 赔率 平:"+touzhu_box.select("div.rangqiuspf div.ping div.peilv").text());
			System.out.print(" 让球 赔率 客胜:"+touzhu_box.select("div.rangqiuspf div.fu div.peilv").text());
			
			System.out.print(" 比赛结果:"+touzhu_box.select("div.more div.more_bg p.p1").text());
			System.out.println();
			System.out.println("=============================================");
		}
		wc.close();
	}

}
